#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end(), [](vector<int>& a1, vector<int>& a2) {
            return a1[0] < a2[0];
            });
        int ans = 0, n = intervals.size(), right = intervals[0][1];
        vector<int> dp(n, 1);
        for (int i = 1; i < intervals.size(); ++i) {
            if (intervals[i][0] < right) {
                ++ans;
                right = min(right, intervals[i][1]);
            }
            else
                right = intervals[i][1];
        }
        return ans;
    }
};